function out = map_color_ratio( patch, target_hist, context_hist)
%Map the patch from RGB color to color ratio feature
    index_patch = floor(double(patch(:,:,1))/16)*256 + floor(double(patch(:,:,2))/16)*16 + floor(double(patch(:,:,3))/16) + 1;
    index_patch(find(index_patch==0))=1;
    out = zeros(size(patch,1),size(patch,2));
    
    context_hist(find(context_hist==0))=1;
    ratio_table = sqrt(target_hist ./ context_hist);
    
    norm = max(ratio_table);
    
    for y = 1:size(patch,1)
        for x = 1:size(patch,2)
            if ratio_table(index_patch(y,x))~=0
                out(y,x) = ratio_table(index_patch(y,x))/norm;
            end
        end
    end
end

